<?php 
//新闻的添加
 include_once("./com.php");
function msg($msg, $url=''){
		if($url == ''){
			$ad = "window.history.go(-1)";
		}else{
			$ad = "window.location.href='{$url}'";
		}
		exit("<script>alert('{$msg}');{$ad};</script>");
	}

 error_reporting(E_ALL^E_NOTICE^E_WARNING);
date_default_timezone_set("PRC");
 $res="select * form news";
 $rty=mysql_query($res);

 	if(isset($_POST['sub'])){
 		$ntitle = $_POST['ntitle'];

 		$nimg = $_FILES['nimg'];
 		$nimg_str = implode("-",$nimg['name']);
 		$nimgsimg = count($nimg);
 		$path = "../uploads1";
 		for($a = 0;$a < $nimgsimg;$a++){
 			$n_img = $nimg['name'][$a];
 			$tmp = $nimg['tmp_name'][$a];
 			move_uploaded_file($tmp,$path."/".$n_img);
 		};

 		$nname = $_POST['nname'];
 		$ndescp = strip_tags($_POST['ndescp']);
 		$nkeyword = $_POST['nkeyword'];
 		if (empty($_POST['ntitle'])) {
		msg('新闻标题不能为空');
	}
		if (empty($_POST['nname'])) {
		msg('新闻作者不能为空');
	}
if (empty($_POST['ndescp'])) {
		msg('新闻内容不能为空');
	}


 		$nem = "insert into news(ntitle,nimg,nname,ntime,number,ndescp,nkeyword)values('$ntitle','$nimg_str','$nname',now(),0,'$ndescp','$nkeyword')";
 		$nme=mysql_query($nem);
 		if(mysql_affected_rows()>0){
 			echo "<script>
				alert('添加成功')
				location.href='news.php'
				</script>";
 		}else{
 			echo "<script>
				alert('添加失败')
				location.href='news_add.php'
				</script>";
				
 		}

 	}


 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加新闻</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			<form  action="" method="post" enctype="multipart/form-data">
			<tr>
				<td width="100px;">新闻标题:</td>
				 <td><input type="text" name="ntitle" value=""></td>
			</tr>				
			<tr>
				 <td>新闻作者：</td>
				 <td><input type="text" name="nname" value=""></td>
			</tr>  		
			<tr>
				<td>关键字：</td>
				<td><input type="text" name="nkeyword" value=""></td>
			</tr>
			<tr>
				 <td>新闻图片：</td>
				 <td><input type="file" name="nimg[]" value="" multiple></td>
			</tr> 
			<tr>
				<td>新闻内容：</td>
				<td>
				<?php
				include_once("./fckeditor/fckeditor.php");
				$fckeditor = new FCKeditor("ndescp");//定义默认值 name
				$fckeditor->Width = "300px";//定义编辑器的宽度
				$fckeditor->Height = "200px";//定义编辑器的高度
				$fckeditor->Value = "";//定义默认值
				$fckeditor->BasePath='./fckeditor/';
				$fckeditor->ToolbarSet = "Basic";
				$fckeditor->Create();//创建编辑器
				?>
				</td>				 
			</tr>  
			<tr>
				 <td colspan="2" align="center" height="40px">
				 	<input type="submit" name="sub" value=" 添加 " class="coolbt2"></td>
			  </tr>
		</form>
			</tr>		
		</table>
	</td>
  </tr>
</table>
</body>
</html>